#include "Document.h"

Document::Document(string xml):root(NULL) {
	unsigned int tagStart = xml.find_first_of('<', 0);
			if (tagStart == string::npos) {
				return;
			}
			unsigned int tagEnd = xml.find_first_of('>', tagStart);
			string tag = xml.substr(tagStart + 1, tagEnd - tagStart - 1);
	root = new Element(tag);
	xml = xml.substr(tagEnd + 1,xml.length());
	string& body = check(xml,'l');
	trunk->push(body);
}

Element* Document::getDocumentElement() {
	return root;
}
void Document::createElement(string name){
	
}
string Document::check(string xml,char pos){
	string a = "<";				//<****>
	char b = '>';
	if(pos == 'r'){				//</****>
		a = "</";
	}
	if(pos =='m'){				//<>****</>
		a = ">";
		b = '<';
	}
	unsigned int tagStart = xml.find_first_of(a, 0);
		if (tagStart == string::npos) {
			return NULL;
		}
		unsigned int tagEnd = xml.find_first_of(b, tagStart);
		string content = xml.substr(tagStart + 1, tagEnd - tagStart - 1);				//content = ****
		return content;
}

